home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1086 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.6 KB  |  67 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
  3. Newsgroups: comp.std.c++
  4. Subject: How it auto_ptr currently defined?
  5. Date: 15 Apr 1996 09:35:51 PDT
  6. Organization: FakultΣt fⁿr Mathematik und Informatik
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4ko4cv$ao7@news.BelWue.DE>
  9. Reply-To: dietmar.kuehl@uni-konstanz.de
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. Summary: How are the copy semantics of 'auto_ptr' currently defined?
  12. Keywords: auto_ptr, copy ctor
  13. X-Original-Date: 13 Apr 1996 11:49:51 GMT
  14. X-Newsreader: TIN [version 1.2 PL2]
  15. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  16.     iQBVAwUBMXJ66Ey4NqrwXLNJAQEzHQH+KuFE9qOMouQD1z98VXV7hdfWugd1iR6h
  17.     h0f6mQCv8X1Km3EQiaWKFzflELyDi9YK28jKjY/ikfO9o/Z2qrIzTg==
  18.     =g6cc
  19. Originator: austern@isolde.mti.sgi.com
  20.  
  21. Hi,
  22.  
  23. gregor@netcom.com (Greg Colvin) recently posted a sample implementation
  24. of 'auto_ptr' to this forum. With his implementation, the following
  25. code would be well defined:
  26.  
  27.   #include <auto_ptr>
  28.  
  29.   auto_ptr<int> f(auto_ptr<int> ptr) { return ptr; }
  30.  
  31.   int main()
  32.   {
  33.     auto_ptr<int> p1(new int(17));
  34.     auto_ptr<int> p2 = f(p1);
  35.     return *p1;
  36.   }
  37.  
  38. The key point I'm confused about, is that 'p1' holds a valid pointer
  39. even after copying the pointer when creating the argument for the
  40. function 'f()': The 'get()' member function of an 'auto_ptr' apparently
  41. returns the correct value even if the pointer is not owned by the
  42. 'auto_ptr' (in the above case, the pointer is owned by 'p2' not by
  43. 'p1'). This might result in an 'auto_ptr' holding a stale pointer.
  44.  
  45. As I have no access to the changes made at the last committee meeting,
  46. my question is this: Is the above code required to be well defined for
  47. a standard conforming implementation? The thread where Greg Colvin
  48. posted his version of 'auto_ptr' implies that the standard will require
  49. the above code to be well defined but there was no explicit statement
  50. about this. The above code resulted in undefined behavior according to
  51. the April DWP (because the copy ctor of 'auto_ptr' was defined to
  52. implicitly call 'release()').
  53.  
  54. Thank you very much for any responses
  55.     dk
  56. --
  57. dietmar.kuehl@uni-konstanz.de
  58. http://www.informatik.uni-konstanz.de/~kuehl/
  59. I am a realistic optimist - that's why I appear to be slightly pessimistic
  60. ---
  61. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  62.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  63.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  64.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  65.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  66. ]
  67.